﻿using CCManger.Common.Message;
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;

namespace CCManger.Common.Coder
{
    public class CommonEncoder<T> : MessageToByteEncoder<T>
    {
        protected override void Encode(IChannelHandlerContext context, T message, IByteBuffer output)
        {
            //序列化类
            byte[] messageBytes = MessagePackHelper.SerializeToBinary(message);
            IByteBuffer initialMessage = Unpooled.Buffer(messageBytes.Length);
            initialMessage.WriteBytes(messageBytes);

            output.WriteBytes(initialMessage);
        }
    }
}